<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
<ui:composition template="../template/layout.xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets">
	<ui:param name="pageHeaderTitle" value="Edit user" />
	<ui:param name="pageTitle" value="#{editUserBean.editMode ? 'Edit user' : 'Create user'}" />
	<ui:define name="content">
		<div id="inner_content">
			<h:form id="userForm">
				<h:panelGrid columns="2"
					columnClasses="createUserGridColumn1, createUserGridColumn2"
					cellpadding="6" style="table-layout: fixed">
					<h:panelGroup>
						<p:outputLabel value="Login:" for="login" />
						<br />
						<p:inputText id="login" value="#{editUserBean.user.name}" maxlength="30">
							<f:attribute name="editMode" value="#{editUserBean.editMode}" />
							<f:validator validatorId="loginValidator" />														
						</p:inputText>
					</h:panelGroup>
					
					<h:panelGroup id="loginMsg">
						<br />
						<p:message for="login" />
					</h:panelGroup>

					<h:panelGroup>
						<p:outputLabel value="Password:" for="pass" />
						<br />
						<p:password id="pass" value="#{editUserBean.user.pass}" maxlength="50" redisplay="true"/>
					</h:panelGroup>
					
					<h:panelGroup id="passMsg">
						<br />
						<p:message for="pass" />
					</h:panelGroup>										
										
					<h:panelGroup>
					<p:outputLabel value="User roles:" for="selectRoles" />							
					<p:selectManyCheckbox id="selectRoles" value="#{editUserBean.user.roles}"  
			            layout="pageDirection" converter="stringToRoleConverter" style="padding-top: 10px">  
			            <f:selectItems value="#{editUserBean.roleList}" />
			            <f:attribute name="collectionType" value="java.util.ArrayList" />
       				</p:selectManyCheckbox>  
					</h:panelGroup>
					
					<h:panelGroup>
					</h:panelGroup>

					<h:panelGroup>
						<br />
						<p:commandButton value="Submit"
							action="#{editUserBean.editUser()}"
							styleClass="pCommandButton" update=":userForm:loginMsg, :userForm:passMsg, :menu_info"/>
					</h:panelGroup>
					
					<h:panelGroup>
					</h:panelGroup>									
					
				</h:panelGrid>
				</h:form>
						<h:form>
						<p:commandButton value="Delete"
							onclick="confirmation.show();return false;" styleClass="pDeleteButton" rendered="#{editUserBean.editMode}" />
	
						<p:confirmDialog message="Are you sure want to delete user?"
							widgetVar="confirmation">
							<p:commandButton value="Yes" onclick="confirmation.hide()"
								actionListener="#{editUserBean.deleteUser}">
							</p:commandButton>
							<p:commandButton value="No" onclick="confirmation.hide()"
								type="button" />							
						</p:confirmDialog>
					</h:form>
					
					<br />
					<h:form>
						<p:commandLink value="Invalidate user session" style="padding-left: 8px" action="#{editUserBean.invalidateUserSession}" />
					</h:form>		
					
		<br /> <br />				
		
		<h:panelGroup id="menu_info" layout="block">
			<p:messages />
		</h:panelGroup>		
		</div>
	</ui:define>
<ui:define name="footer">	
	<ui:param name="navBean" value="#{editUserBean}" />
	<ui:param name="navAction" value="goBack" />
	<ui:param name="navTitle" value="Back" />
	<ui:include src="/template/footer_bean_navigation.xhtml" />
</ui:define>
</ui:composition>
</html>